
<%@page contentType="text/html" pageEncoding="utf-8"%>
<!DOCTYPE html>
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8">
<title>管理员入口</title>
<style type="text/css">
body {
	font: normal 16px auto "Trebuchet MS", Verdana, Arial, Helvetica,
		sans-serif;
	text-align: center;
}

#container {
	margin-left: 30%;
	margin-right: 18%;
	width: 50%;
	height: 60%;
	display: block;
	vertical-align: middle;
}

.con {
	padding-top: 3em;
}

.label {
	padding-top: 3em;
}

#lab {
	text-align: left;
	width: 4em;
	float: left;
}

#lab2 {
	text-align: left;
	width: 12em;
	float: right;
}

#but {
	text-align: left;
	width: 10em;
	padding-left: 12em;
	padding-top: 3em;
}
</style>
<script type="text/javascript">
        
            function load(){
                var numstr = "";
                var character = "ABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789";
                for(var i=0;i<4;i++){
                    var j = Math.floor((Math.random()*36));  
                    numstr += character.charAt(j);
                }                                
                loginForm.imgstr.value = numstr;
                document.cookie = "imgstr=" +numstr;                                               
                loginForm.img1.src= "img.jsp?"+Math.random();
      
            }
            function dataCheck(){
                var username = loginForm.username.value;
                var password = loginForm.passwd.value;
                var ok = true;
                var sys = String(loginForm.imgstr.value); 
                var res = String(loginForm.input.value).toUpperCase();   
                var identity = loginForm.identity.value;
                if(username != "" && password != "" ){
                    var format1 = new RegExp("^[\\w]{2,18}$");               
                    if(!format1.test(username)){
                        alert("\u7528户名格式错误！");
                        loginForm.username.focus();
                        ok = false;
                    }
                    else if(!format1.test(password)){
                        alert("\u5bc6码格式错误！");
                        loginForm.passwd.focus();
                        ok = false;
                    }
                    if(sys != res ){
                        alert("\u9a8c证码错误!");
                        loginForm.input.focus();
                        ok = false;
                    }  
                }               
                else if(username == "" || username == null){               
                    alert("\u8bf7输入用户名！");
                    loginForm.username.focus();
                    ok = false;
                }
                else if(password == "" || password == null){
                    alert("\u8bf7输入密码");
                    loginForm.passwd.focus();
                    ok = false;
                }
                return ok;
            }
            function showMessage(){
            	alter("用户名或密码错误！");
            }
            function showGrade(identity){          	
            	if(identity == "1"){
            		document.getElementById("gradediv").style.display='inline';
            	}else{
            		document.getElementById("gradediv").style.display='none';
            	}
            }
        </script>
</head>
<body>
	<div id="container">
		<form name="loginForm" method="post" action="servlet/AdminLoginServlet"
			onSubmit="return dataCheck()">
			<div id="lab">
				<div class="label">
					<label> 用户名： </label>
				</div>
				<div class="label">
					<label> 密码： </label>
				</div>
				<div class="label">
					<label> 验证码： </label>
				</div>				
			</div>
			<div id="lib2">
				<div class="con">
					<input type="text" name="username" /> <input type="hidden"
						name="imgstr" id="hid1" value="" />
				</div>
				<div class="con">
					<input type="password" name="passwd" />
				</div>
				<div class="con">
					<input type="text" style="width: 50px;" name="input" /> <img
						alt="正在生成" src="img.jsp" name="img1" /> <a
						href="javascript:load();">看不清楚</a>
				</div>
			</div>
			<div id="but">
				<input type="submit" value="提交" /> &nbsp;&nbsp; <input type="reset"
					value="取消" />
			</div>
		</form>
	</div>
	<script>
        load();
    </script>
	<%
	    if (request.getQueryString() != null) {
			String str = request.getParameter("error");
			if ("1".equals(str)) {
			    out.println("<script>alert('用户名或密码错误！')</script>");
			} else if ("2".equals(str)) {
			    out.println("<script>alert('用户名，密码不能为空！')</script>");
			}else if ("3".equals(str)) {
			    out.println("<script>alert('用户身份错误！')</script>");
			}
	    }
	%>
</body>
</html>
